#include "./xyz.h"

int mds_xyz_save(const char          *filename, 
				 const mds_vector_set vec, 
				 const size_t         num,
				 const char          *comment,
				 int                  append)
{
	FILE *fp      = NULL;
	char  mode[4] = { (char)(append ? 'a' : 'w'), 'b', 0, 0 };
	
	assert(filename);
	assert(vec!=NULL);
	assert(num>0);
	
	if( NULL == ( fp = fopen( filename, mode ) ) )
	{
		return -1;
	}
	else 
	{
		size_t i;
		fprintf( fp, "%u\n", (unsigned)num );
		if( comment ) fprintf( fp, "%s\n", comment ); else fprintf( fp, "\n");
		for( i=0; i <num; ++i )
		{
			const mds_vector *p = & vec[i];
			fprintf( fp, "H %g %g %g\n", 10 * p->x, 10 * p->y, 10 * p->z );
		}
		fclose(fp);
	}

	return 0;
	
}

